import { detailConfig, dictcodes } from '@/views/datacenter/basicData/oldman/config'
import { getAreaObj } from '@/utils/util'

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	labelWidth: '110px',
	column: [
		{
			label: '证件号码',
			prop: 'idCard',
			type: 'input',
			span: 6,
		},
		{
			label: '户籍地区',
			prop: 'crAreas',
			checkStrictly: true,
			type: 'AplidAreaSelect',
			span: 6,
		},
		{
			label: '姓名',
			prop: 'name',
			type: 'input',
			span: 6,
		},
		{
			label: '联系方式',
			prop: 'telephone',
			type: 'input',
			span: 6,
		},
		{
			label: '人员类型',
			prop: 'elderlyType',
			type: 'remoteSelect',
			code: 'ELDERLY_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			teleported: false,
			multiple: false,
			span: 6,
		},
		{
			label: '评估等级',
			prop: 'cityLevel',
			propName: 'cityLevelLabel',
			type: 'remoteSelect',
			code: 'ACCESS_LEVEL_CITY',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 6,
		},
		{
			label: '更新状态',
			prop: 'serviceObjectStatus',
			type: 'select',
			dicData: [
				{ label: '新入院', value: '新入院' },
				{ label: '出院', value: '出院' },
				{ label: '正常', value: '正常' },
			],
			span: 6,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{
			label: '姓名',
			prop: 'name',
		},
		{ label: '证件号码', prop: 'idCard', plusXing: '2,2' },
		{
			label: '性别',
			prop: 'genderLabel',
		},
		{ label: '年龄', prop: 'age' },
		{ label: '联系方式', prop: 'telephone', plusXing: '5,2' },
		{ label: '现居地区', prop: 'tableAreaName' },
		{ label: '评估能力等级', prop: 'cityLevelLabel' },
		{
			label: '人员类型',
			prop: 'elderlyType',
			custome: 'dict',
			code: 'ELDERLY_TYPE',
		},
		{
			label: '查看状态',
			prop: 'viewStatus',
			span: 8,
		},
		{
			label: '服务对象状态',
			prop: 'serviceObjectStatus',
			span: 8,
			dicData: [
				{ label: '新入院', value: '新入院' },
				{ label: '出院', value: '出院' },
				{ label: '正常', value: '正常' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_dpServiceObject_monthPage',
}
export const baseConfig = {
	pageName: '服务对象信息',
	dictcodes: dictcodes,
	rowKey: 'id',
	tipLabel: 'name',
	exportMqTopic: '/ning/export/',
	showHeaderTitle: false,
	api,
	auth: {
		...api,
	},
	menuBtn: [
		{
			icon: 'detail',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: '',
			text: true,
			show: true,
		},
	],
	dialogConfig: {
		width: '75%',
	},
	detailConfig: {
		customeHeader: {
			...detailConfig.customeHeader,
			menuBtn: [],
		},
	},
	searchConfig,
	tableConfig,
	beforeOnLoadFormate: async (params) => {
		const areasObj: any = getAreaObj(params.areas, '')
		const crAreasObj: any = getAreaObj(params.crAreas, 'cr')
		return Promise.resolve({
			...params,
			...areasObj,
			...crAreasObj,
			areas: undefined,
			crAreas: undefined,
			buildInfo: undefined,
			buildInfoName: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const crAreaName = getAreaObj(item, 'cr')
			const areas_name = getAreaObj(item, '')
			return {
				...item,
				areas_name,
				crAreaName,
				tableAreaName: [item.areaName, item.streetName, item.communityName].filter(Boolean).join(''),
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
}
